package com.polytech.business;

import java.util.List;

import sun.font.CreatedFontTracker;

import com.polytech.dao.PostDao;
import com.polytech.dao.TopicDao;
import com.polytech.model.Membre;
import com.polytech.model.Post;
import com.polytech.model.Topic;

public class DefaultForumManager implements ForumManager {

	private TopicDao topicDao;
	private PostDao postDao;
	
	public DefaultForumManager(TopicDao topicDao,PostDao postDao) {
		this.topicDao=topicDao;
		this.postDao=postDao;
	}
	@Override
	public void createTopic(Topic topic,String userName) {
		topic.setCreator(new Membre(userName, "*"));
		topicDao.insert(topic);
	}

	@Override
	public Topic findTopic(int id) {
		return topicDao.select(id);
	}

	@Override
	public List<Topic> findTheLastThreeTopics() {
		return topicDao.findTheLastThreeTopic();
	}

	@Override
	public List<Topic> findAllTopics() {
		return topicDao.findAllTopics();
	}

	@Override
	public void createPost(Post post,int idTopic, String userName) {
		postDao.insert(post, userName,idTopic);
	}

	@Override
	public Post findPost(int id) {
		return postDao.select(id);
	}

	@Override
	public List<Post> findAllTopicPosts(int idTopic) {
		return postDao.findAllTopicPosts(idTopic);
	}

}
